angular.module('imsApp').controller('copyScreenController', ['$scope', '$rootScope', '$state', 'copyScreenManager','AdvertisersManager', function ($scope, $rootScope, $state, copyScreenManager,AdvertisersManager) {
    $scope.search = {pageNo:$state.params.pageNo || 1,
        pageSize:$state.params.pageSize||10,
        advertiserId:$state.params.advertiserId,
        campaignName:$state.params.campaignName,
        startDay:$state.params.startDay||null,
        endDay:$state.params.endDay||null
    };

    $scope.typeChange=function (id) {
        if (id) {
            $scope.search.advertiserId = id;
        } else {
            $scope.search.advertiserId = null;
        }
        $state.go($state.current.name, $scope.search)
    };

    $scope.searchClick=function(keyword){
        $scope.search.campaignName=keyword;
        $scope.search.pageNo=1;
        $state.go($state.current.name,$scope.search);
    };

    $scope.rangeDate = {
        startDate: $scope.search.startDay ? moment($scope.search.startDay).format('X') : null,
        endDate: $scope.search.endDay ? moment($scope.search.endDay).format('X') : null,
        onSelected: function (data, scope) {  //时间选择确认事件
            $scope.search.startDay=data.startDate?moment(new Date(parseFloat(data.startDate)*1000)).format("YYYY-MM-DD"):null;
            $scope.search.endDay=data.endDate?moment(new Date(new Date(parseFloat(data.endDate)*1000))).format("YYYY-MM-DD"):null;
            $state.go($state.current.name, $scope.search)
        }
    };

    $scope.paginationConf = {
        currentPage: $state.params.pageNo || 1,
        itemsPerPage: $state.params.pageSize || 10,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name, $scope.search)
        }
    };

    copyScreenManager.copyScreenList([$scope.search.pageNo, $scope.search.pageSize], $scope.search).then(function (result) {
        $scope.copyScreenList = result.data.pageList;
        $scope.paginationConf.totalItems = result.data.total;
    });

    AdvertisersManager.advertiserSimpleList([1,100]).then(function (result) {
        $scope.advertiserSimpleList=result.data.pageList;
        $scope.advertiserSimpleList=[{id:null,name:"全部"}].concat($scope.advertiserSimpleList)
    });


}]);

